//定义localStorage中token等的常量键名
const TokenKey = 'accessToken'
const RefreshTokenKey = 'refreshToken'
    //定义localStorage中登入的用户信息常量键名
var UserInfo = "userInfo"


// 设置保存token和refreshToken
export function setToken(token, refreshToken) {
    localStorage.setItem(TokenKey, token)
    localStorage.setItem(RefreshTokenKey, refreshToken)
}


// 获取token
export function getToken() {
    return localStorage.getItem(TokenKey)
}


// 获取refreshToken
export function getRefreshToken() {
    return localStorage.getItem(RefreshTokenKey)
}




// 清除token和refreshToken
export function clearToken() {
    localStorage.removeItem(TokenKey)
    localStorage.removeItem(RefreshTokenKey)
}


//登入保存用户信息
export function setUserInfo(userinfo) {
    //localStorage存储对象需要Json化，不然就是[object，object]
    localStorage.setItem(UserInfo, JSON.stringify(userinfo))

}

//获取登入的用户ID和头像ID等等信息(再次刷新页面或者...)
export function getUserInfo() {
    return localStorage.getItem(UserInfo)
}

//退出登入清除用户信息
export function clearUserInfo() {
    localStorage.removeItem(UserInfo)
}


// 判断有无登入搭配导航守卫使用
export function isAuth() {
    let token = getToken()
    if (token) {
        return true
    } else {
        return false
    }
}